home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / cview.jar / content / cview / cview-trees.js < prev    next >
Encoding:
JavaScript  |  2004-04-18  |  7.5 KB  |  289 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is mozilla.org code.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Netscape Communications Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 1998
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *   Robert Ginda, rginda@netscape.com, original author
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  28.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. function initTrees()
  41. {
  42.     const ATOM_CTRID = "@mozilla.org/atom-service;1";
  43.     const nsIAtomService = Components.interfaces.nsIAtomService;
  44.  
  45.     var atomsvc =
  46.         Components.classes[ATOM_CTRID].getService(nsIAtomService);
  47.  
  48.     cview.interfaceView.atomInterface = atomsvc.getAtom("interface");
  49.  
  50.     cview.componentView.atomComponent = atomsvc.getAtom("component");
  51.     cview.componentView.atomMethod    = atomsvc.getAtom("method");
  52.     cview.componentView.atomInterface = atomsvc.getAtom("interface");
  53.  
  54.     var i;
  55.     var ary = new Array();
  56.     var names = keys(Components.interfaces).sort();
  57.     for (i in names)
  58.     {
  59.         ary.push(new InterfaceRecord (names[i]));
  60.     }
  61.  
  62.     cview.interfaceView.childData.setSortColumn ("ifc-name");
  63.     cview.interfaceView.childData.appendChildren(ary, true);
  64.     
  65.     ary = new Array();
  66.     names = keys(Components.classes).sort();
  67.     for (i in names)
  68.     {
  69.         ary.push(new ComponentRecord (names[i]));
  70.     }
  71.  
  72.     cview.componentView.childData.setSortColumn ("cmp-name");
  73.     cview.componentView.childData.appendChildren (ary, true);
  74.        
  75.     var tree = document.getElementById("component-tree");
  76.     tree.treeBoxObject.view = cview.componentView;
  77.  
  78.     tree = document.getElementById("interface-tree");
  79.     tree.treeBoxObject.view = cview.interfaceView;
  80.  
  81. }
  82.  
  83. var interfaceShare = new Object();
  84.  
  85. cview.interfaceView = new TreeOView(interfaceShare);
  86.  
  87. cview.interfaceView.getRowProperties =
  88. function ifc_getrow (index, properties)
  89. {    
  90.     properties.AppendElement(cview.interfaceView.atomInterface);
  91. }
  92.  
  93. function InterfaceRecord (ifc)
  94. {
  95.     this.setColumnPropertyName ("ifc-name",   "name");
  96.     this.setColumnPropertyName ("ifc-number", "number");
  97.  
  98.     this.name = ifc;
  99.     this.ifc = Components.interfaces[ifc];
  100.     if (this.ifc)
  101.     {
  102.         this.number = this.ifc.number;
  103.     }
  104.     else
  105.     {
  106.         this.number = "???";
  107.         this.isBroke = true;
  108.     }
  109.  
  110.     this.sortName = this.name;
  111.     this.sortNumber = this.number;
  112. }
  113.  
  114. InterfaceRecord.prototype = new TreeOViewRecord(interfaceShare);
  115.  
  116. InterfaceRecord.prototype.getText =
  117. function cir_text ()
  118. {
  119.     return ("Interface name - " + this.name + "\n" +
  120.             "Interface ID   - " + this.number + "\n");
  121. }
  122.  
  123. var componentShare = new Object();
  124.  
  125. cview.componentView = new TreeOView(componentShare);
  126.  
  127. cview.componentView.getCellProperties =
  128. function cmp_getrow (index, col, properties)
  129. {
  130.     if (col.id != "cmp-name")
  131.         return;
  132.  
  133.     var row = this.childData.locateChildByVisualRow(index);
  134.     if (!row)
  135.         return;
  136.     
  137.     row.getProperties(properties);
  138. }
  139.  
  140. function ComponentRecord (cmp)
  141. {
  142.     this.setColumnPropertyName ("cmp-name",   "name");
  143.     this.setColumnPropertyName ("cmp-number", "number");
  144.  
  145.     this.name = cmp;
  146.     this.cmp = Components.classes[cmp];
  147.     if (this.cmp)
  148.     {
  149.         this.number = this.cmp.number;
  150.     }
  151.     else
  152.     {
  153.         this.number = "???";
  154.         this.isBroke = true;
  155.     }
  156.  
  157.     this.sortName = this.name;
  158.     this.sortNumber = this.number;
  159.     this.reserveChildren();
  160. }
  161.  
  162. ComponentRecord.prototype = new TreeOViewRecord(componentShare);
  163.  
  164. ComponentRecord.prototype.getProperties =
  165. function cr_getprops (properties)
  166. {
  167.     properties.AppendElement(cview.componentView.atomComponent);
  168. }
  169.  
  170. ComponentRecord.prototype.getText =
  171. function cr_text ()
  172. {
  173.     return ("Contract ID    - " + this.name + "\n" +
  174.             "Class ID       - " + this.number + "\n");
  175. }
  176.  
  177. ComponentRecord.prototype.onPreOpen =
  178. function cr_preopen ()
  179. {
  180.     if ("populated" in this)
  181.         return;
  182.     
  183.     var ex;
  184.     cls = Components.classes[this.name];
  185.     if (!cls)
  186.         return;
  187.  
  188.     try
  189.     {
  190.         cls = cls.createInstance();
  191.     }
  192.     catch (ex)
  193.     {
  194.         dd("caught " + ex + " creating instance of " + cls);
  195.         return;
  196.     }
  197.  
  198.     for (var i in Components.interfaces)
  199.     {
  200.         try
  201.         {
  202.             var ifc = Components.interfaces[i];
  203.             cls = cls.QueryInterface(ifc);
  204.             this.appendChild (new ChildInterfaceRecord(ifc, cls));
  205.         }
  206.         catch (ex)
  207.         {
  208.         }
  209.         
  210.     }
  211.  
  212.     this.populated = true;    
  213. }
  214.  
  215. function ChildInterfaceRecord (ifc, instance)
  216. {
  217.     this.setColumnPropertyName ("cmp-name",   "name");
  218.     this.setColumnPropertyName ("cmp-number", "number");
  219.  
  220.     this.instance = instance;
  221.     this.ifc = ifc;
  222.     if (ifc)
  223.     {
  224.         this.name = ifc.name;
  225.         this.number = ifc.number;
  226.     }
  227.     else
  228.     {
  229.         this.name ="???";
  230.         this.number = "???";
  231.         this.isBroke = true;
  232.     }
  233.  
  234.     this.sortName = this.name;
  235.     this.sortNumber = this.number;
  236.     this.reserveChildren();
  237. }
  238.  
  239. ChildInterfaceRecord.prototype = new TreeOViewRecord(componentShare);
  240.  
  241. ChildInterfaceRecord.prototype.getText =
  242. function cir_text ()
  243. {
  244.     return (this.parentRecord.getText() +
  245.             "Interface name - " + this.name + "\n" +
  246.             "Interface ID   - " + this.number + "\n");
  247. }
  248.  
  249. ChildInterfaceRecord.prototype.onPreOpen =
  250. function cir_preopen ()
  251. {
  252.     if ("populated" in this)
  253.         return;
  254.  
  255.     for (var m in this.instance)
  256.         this.appendChild(new MethodRecord(m));
  257.  
  258.     this.populated = true;
  259. }
  260.  
  261. ChildInterfaceRecord.prototype.getProperties =
  262. function cir_getprops (properties)
  263. {
  264.     properties.AppendElement(cview.componentView.atomInterface);
  265. }
  266.  
  267. function MethodRecord (name)
  268. {
  269.     this.setColumnPropertyName ("cmp-name",   "name");
  270.     this.name = name;
  271.     this.sortName = this.name;
  272. }
  273.  
  274. MethodRecord.prototype = new TreeOViewRecord(componentShare);
  275.  
  276. MethodRecord.prototype.getText =
  277. function mr_text ()
  278. {
  279.     return (this.parentRecord.getText() +
  280.             "Methods        - " + 
  281.             keys(this.parentRecord.instance).join("\n                 "));
  282. }
  283.  
  284. MethodRecord.prototype.getProperties =
  285. function mr_getprops (properties)
  286. {
  287.     properties.AppendElement(cview.componentView.atomMethod);
  288. }
  289.